package com.sskj.finance.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.SPUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.finance.http.HttpConfig;
import com.sskj.finance.ui.activity.AppointmentBuyActivity;
import com.sskj.lib.SPConfig;
import com.sskj.lib.http.JsonCallBack;


public class AppointmentBuyActivityPresenter extends BasePresenter<AppointmentBuyActivity> {


    /**
     * 认购理财产品
     *
     * @param id   红利记录id
     * @param num  认购数量
     * @param code 短信验证码，type=5
     * @return
     */
    public void createOrder(String id, String num, String code) {
        httpService.createOrder(id, num, code).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                ToastUtil.showShort(httpData.getMsg());
                if (httpData.getStatus() == HttpConfig.OK) {
mView.buySuccess();
                }
            }
        });
    }

    public void sendCode() {
        String mobile = SPUtil.get(SPConfig.MOBILE, "");
        httpService.sendSms(mobile)
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        ToastUtil.showShort(httpData.getMsg());
                        if (httpData.getStatus() == HttpConfig.OK) {

                            mView.sendCheckCodeSuccess();
                        } else {
                            mView.sendCheckCodeFail();
                        }
                    }

                    @Override
                    public void onError(Response<HttpData> response) {
                        super.onError(response);
                        mView.sendCheckCodeFail();
                    }
                });
    }
}
